home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / apport / apportcheckresume < prev    next >
Encoding:
Text File  |  2009-09-25  |  2.9 KB  |  90 lines

  1. #!/usr/bin/python
  2. import os
  3. import os.path
  4. import sys
  5. import datetime
  6. import commands
  7.  
  8. import apport.hookutils
  9.  
  10. from gettext import gettext as _
  11.  
  12. def main(argv=None):
  13.  
  14.     if argv is None:
  15.         argv = sys.argv
  16.  
  17.     try:
  18.         from apport.packaging_impl import impl as packaging
  19.         if not packaging.enabled():
  20.             return -1
  21.  
  22.         import apport.report
  23.         pr = apport.report.Report(type='KernelOops')
  24.  
  25.         libdir = '/var/lib/pm-utils'
  26.         flagfile = libdir + '/status'
  27.         stresslog = libdir + '/stress.log'
  28.         hanglog = libdir + '/resume-hang.log'
  29.  
  30.         pr.add_os_info()
  31.         pr.add_proc_info()
  32.         pr.add_user_info()
  33.         pr['Package'] = 'linux-image-' + os.uname()[2]
  34.  
  35.         # grab the contents of the suspend/resume flag file
  36.         apport.hookutils.attach_file_if_exists(pr, flagfile, 'Failure')
  37.  
  38.         # grab the contents of the suspend/hibernate log file
  39.         failurelog = '/var/log/pm-' + pr['Failure'] + '.log'
  40.         apport.hookutils.attach_file_if_exists(pr, failurelog, 'SleepLog')
  41.  
  42.         # grab the contents of the suspend/resume stress test log if present.
  43.         if os.path.exists(stresslog):
  44.             apport.hookutils.attach_file_if_exists(pr, stresslog, 'StressLog')
  45.  
  46.         # Ensure we are appropriatly tagged.
  47.         pr['Tags'] = 'resume ' + pr['Failure']
  48.  
  49.         # Record the failure mode.
  50.         pr['Failure'] += '/resume'
  51.  
  52.         # If we had a late hang pull in the resume-hang logfile.  Also
  53.         # add an additional tag so we can pick these out.
  54.         if os.path.exists(hanglog):
  55.             apport.hookutils.attach_file_if_exists(pr, hanglog, 'ResumeHangLog')
  56.             pr['Tags'] += ' resume-late-hang'
  57.  
  58.         # Generate a sensible report message.
  59.         if pr['Failure'] == 'suspend/resume':
  60.             pr['Annotation'] = _('This occured during a previous suspend and prevented it from resuming properly.')
  61.         else:
  62.             pr['Annotation'] = _('This occured during a previous hibernate and prevented it from resuming properly.')
  63.  
  64.         # If we had a late hang make sure the dialog is clear that they may
  65.         # not have noticed.  Also update the bug title so we notice.
  66.         if os.path.exists(hanglog):
  67.             pr['Annotation'] += '  ' + _("The resume processing hung very near the end and will have appeared to have completed normally.")
  68.             pr['Failure'] = 'late resume'
  69.  
  70.         if pr.check_ignored():
  71.             return 0
  72.  
  73.         nowtime = datetime.datetime.now()
  74.         pr_filename = '/var/crash/susres.%s.crash' % (str(nowtime).replace(" ","_"))
  75.         report_file = os.fdopen(os.open(pr_filename, os.O_WRONLY|os.O_CREAT|os.O_EXCL), 'w')
  76.         os.chmod(pr_filename, 0600)
  77.         try:
  78.             pr.write(report_file)
  79.         finally:
  80.             report_file.close()
  81.         return 0
  82.     except:
  83.         print "apportcheckresume failed"
  84.         raise
  85.  
  86. if __name__ == "__main__":
  87.     sys.exit(main())
  88.  
  89.  
  90.